﻿using GRPCClass;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GRPCClass
{
    public class TaskReplyCollection : IList
    {
        public static List<TaskReply> TaskReplyList = new List<TaskReply>();
      
        public object this[int index]
        {
            get
            {
                return TaskReplyList[index];
            }
            set
            {
                TaskReply a= value as TaskReply;
                TaskReplyList[index] = a;
            }
        }

        public int Count
        {
            get
            {
                return TaskReplyList.Count;
            }   
        }

        public object SyncRoot
        {
            get
            {
                return this;
            }
        }

        public bool IsSynchronized
        {
            get
            {
                return false;
            }
        }

        public bool IsReadOnly
        {
            get
            {
                return false;
            }
        }

        public bool IsFixedSize
        {
            get
            {
                return true;
            }
        }
        public Boolean Remove(TaskReply vtaskreply)
        {
            TaskReply ftr = findTaskReply(vtaskreply);
            if (ftr != null)
            {
                TaskReplyList.Remove(ftr);
                return true;
            }
            return false;
        }
        public int AddNew(TaskReply value)
        {
            TaskReplyList.Add(value);
            return 1;
        }
        public int Add(object value)
        {
            TaskReply a = value as TaskReply;
            if (a != null)
            {
                if (findTaskReply(a)==null)
                {
                    TaskReplyList.Add(a); 
                    return 1;
                }
            } 
            return 0;
        }
        public TaskReply findTaskReply(string  id)
        {
            int irow = TaskReplyList.Count;
            for (int i = 0; i < irow; i++)
            {
                if (TaskReplyList[i].ID == id)
                {
                    return TaskReplyList[i];
                }
            }
            return null;
        }

        public TaskReply findTaskReply(TaskReply tr)
        {
            int irow = TaskReplyList.Count;
            for (int i = 0; i < irow; i++)
            {
                if (TaskReplyList[i].ID == tr.ID)
                {
                    return TaskReplyList[i];
                }
            }
            return null; 
        }
        public void Clear()
        {
            TaskReplyList.Clear();
        }

        public bool Contains(object value)
        {
          return  TaskReplyList.Contains(value);
        }

        public void CopyTo(Array array, int index)
        {
            TaskReplyList.CopyTo(array as TaskReply[], index);
        }

        public IEnumerator GetEnumerator()
        {
            return TaskReplyList.GetEnumerator();
        }

        public int IndexOf(object value)
        {
            return TaskReplyList.IndexOf(value as TaskReply);
        }

        public void Insert(int index, object value)
        {
            TaskReplyList.Insert(index, value as TaskReply);
        }

        public void Remove(object value)
        {
            TaskReplyList.Remove(value as TaskReply);
        }

        public void RemoveAt(int index)
        {
            TaskReplyList.RemoveAt(index);
        }
    }
}
